<template>
  <div class="body-container layout-padding">
    <div class="clearfix">
      <el-button size="default" type="primary"  @click="addKaoQinYuan">
        <el-icon><ele-CirclePlus /></el-icon>添加
      </el-button>
    </div>
    <el-table :data="state.kqyObj.list" border style="width: 100%">
      <el-table-column label="制单人姓名" prop="cmaker"></el-table-column>
      <el-table-column label="制单人编号" prop="cmakerno"></el-table-column>
      <el-table-column label="部门id" prop="ideptid"></el-table-column>
      <el-table-column label="考勤部门" prop="ckqbm"></el-table-column>
      <el-table-column label="考勤部门编码" prop="ckqbmbm"></el-table-column>
      <el-table-column label="考勤岗位" prop="cgw"></el-table-column>
      <el-table-column label="企业微信号" prop="cdefine1"></el-table-column>
      <el-table-column label="操作">
        <template v-slot="scope">
          <el-button size="small" type="primary" @click="editKaoQinYuan(scope.row.id)">修改</el-button>
          <el-button size="small" type="danger"  @click="deleteKaoQinYuan(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination class="mt15" background layout="total, prev, pager, next"
                   @current-change="loadKaoQinYuan" @size-change="loadKaoQinYuan" :total="state.kqyObj.total"
                   v-model:current-page="state.sd.pageNum" v-model:page-size="state.sd.pageSize">
    </el-pagination>
    <el-dialog :title="state.popupTitle" v-model="state.entityDetailVisible" :close-on-click-modal="false" width="888px">
      <KqyDetail v-if="state.entityDetailVisible" v-model="state.entityDetailVisible" :entityId="state.popupEntityId"></KqyDetail>
    </el-dialog>
  </div>
</template>

<script setup name="kqyIndex">
import request from '/@/utils/request';
import { ElMessage } from 'element-plus';
import mittBus from '/@/utils/mitt';
import {reactive, ref, onMounted, onUnmounted, defineAsyncComponent} from "vue";
import { useRouter } from "vue-router";
const router = useRouter();

const KqyDetail = defineAsyncComponent(() => import('/@/views/sys/kaoqinyuan/kqyDetail.vue'));
const state = reactive({
  sd: {
    pageNum: 1,
    pageSize: 15
  },
  kqyObj: {},
  entityDetailVisible : false,
  popupTitle : '',
  popupEntityId : 0,
})
const loadKaoQinYuan = ()=>{
  request({
    url: '/kaoqinyuan/pagekaoqinyuan',
    data: state.sd
  }).then(res => {
    const { data } = res
    state.kqyObj = data
  })
}
const addKaoQinYuan = ()=>{
  state.popupEntityId = 0;
  state.popupTitle= "新增考勤员"
  state.entityDetailVisible= true
}
const editKaoQinYuan = (id)=>{
  state.popupEntityId= id;
  state.popupTitle= "修改考勤员"
  state.entityDetailVisible= true
}
const viewKaoQinYuan = (id)=>{
  //router.push({name: 'basedataKaoQinYuanView', params :{id : id} })
}
const deleteKaoQinYuan = (id)=>{
  request({
    url: '/kaoqinyuan/deleteKaoQinYuan',
    data: {id : id}
  }).then(res => {
    if(res.code === '200') {
      ElMessage.success(res.msg)
      loadKaoQinYuan();
    }
  })
}

onMounted(()=>{
  loadKaoQinYuan();
  mittBus.on("kqyadd", ()=>{
    state.sd.pageNum = 1;
    loadKaoQinYuan();
  })
  mittBus.on("kqyedit", ()=>{
    loadKaoQinYuan();
  })
})
onUnmounted(()=>{
  mittBus.off("kqyadd", ()=>{})
  mittBus.off("kqyedit",()=>{})
})

</script>
<style scoped>
</style>
